package com.springboot.demo.controller;


import com.springboot.demo.entity.User;
import com.springboot.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 注解 PathVariable 用于从请求URL中获取参数并映射到方法参数中
 */
@Controller
@RequestMapping("/user/{id}")
public class Sample35Controller {

    @Autowired
    UserService userService;

    @GetMapping(path = "/{type}/get.json")
    @ResponseBody
    public User getUser(@PathVariable Long id, @PathVariable Integer type){
        return userService.getUserById(id);
    }

}
